//@include "lib.jsx"
function addWaterMark() {
    adw(encodeChineseToURL(getPath().scriptFolderPath));
    ///////////////////////////////////////////////////////////////////////////////
    (function make_01544668152928() //填充图案
        {
            try {
                var d = new ActionDescriptor();
                var r = new ActionReference();
                r.putClass(stringIDToTypeID("contentLayer"));
                d.putReference(stringIDToTypeID("null"), r);
                var d1 = new ActionDescriptor();
                var d2 = new ActionDescriptor();
                var d3 = new ActionDescriptor();
                d3.putString(stringIDToTypeID("name"), "Ë®Ó¡");
                d3.putString(stringIDToTypeID("ID"), "5195d964-eee7-ff4c-aaae-0a1153e206bc");
                d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
                d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
                d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
                executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
            } catch (e) {
                if (e.number != 8007) {
                    alert("Line: " + e.line + "\n\n" + e, "Bug!", true);
                    throw (e);
                }
            }
        }
    )();

    ///////////////////////////////////////////////////////////////////////////////
    (function move_62383756646886() //置顶图案
        {
            try {
                var d = new ActionDescriptor();
                var r = new ActionReference();
                r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
                d.putReference(stringIDToTypeID("null"), r);
                var r1 = new ActionReference();
                r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("front"));
                d.putReference(stringIDToTypeID("to"), r1);
                executeAction(stringIDToTypeID("move"), d, DialogModes.NO);
            } catch (e) {
                if (e.number != 8007) {
                    alert("Line: " + e.line + "\n\n" + e, "Bug!", true);
                    throw (e);
                }
            }
        }
    )();

    ///////////////////////////////////////////////////////////////////////////////
    (function set_32701170351356() //透明度15%
        {
            try {
                var d = new ActionDescriptor();
                var r = new ActionReference();
                r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
                d.putReference(stringIDToTypeID("null"), r);
                var d1 = new ActionDescriptor();
                d1.putUnitDouble(stringIDToTypeID("opacity"), stringIDToTypeID("percentUnit"), 15);
                d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layer"), d1);
                executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
            } catch (e) {
                if (e.number != 8007) {
                    alert("Line: " + e.line + "\n\n" + e, "Bug!", true);
                    throw (e);
                }
            }
        }
    )();

}
//导入水印
function adw(path) {
    //alert(encodeChineseToURL(path + getOsSolidus() + "watermark.pat"));
    ///////////////////////////////////////////////////////////////////////////////
    (function set_86533765075728() //
        {

            try {
                var d = new ActionDescriptor();
                var r = new ActionReference();
                r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("pattern"));
                r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
                d.putReference(stringIDToTypeID("null"), r);
                d.putPath(stringIDToTypeID("to"), new File(path + getOsSolidus() + "watermark.pat"));


                d.putBoolean(stringIDToTypeID("append"), true);
                executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
            } catch (e) {
                if (e.number != 8007) {
                    alert("Line: " + e.line + "\n\n" + e, "Bug!", true);
                    throw (e);
                }
            }
        }
    )();

}

//删除水印
function wsd() {

    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putIndex(stringIDToTypeID("pattern"), 14);
        d.putReference(stringIDToTypeID("null"), r);
        executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);
    } catch (e) {   
        if (e.number != 8007) {
            alert("Line: " + e.line + "\n\n" + e, "Bug!", true);
            throw (e);
        }
    }
}

addWaterMark()
wsd()